package com.lianzhihui.romeex.ui.mianfragment;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.google.android.material.tabs.TabLayout;
import com.lianzhihui.romeex.MyApplication;
import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.ui.base.BaseFragment;
import com.lianzhihui.romeex.ui.trade.fragment.ExchangeFragment;
import com.lianzhihui.romeex.ui.trade.fragment.ExtractFragment;
import com.lianzhihui.romeex.ui.trade.fragment.FlowCellFragment;
import com.lianzhihui.romeex.ui.trade.fragment.PledgeFragment;
import com.lianzhihui.romeex.utils.DensityUtil;
import com.lianzhihui.romeex.utils.StatusBarUtil;
import com.lianzhihui.romeex.widget.MyViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @ProjectName: romeex
 * @Package: com.lianzhihui.romeex.ui.mianfragment
 * @ClassName: TradeFragment
 * @Description: java类作用描述
 * @Author: zhanghong
 * @CreateDate: 2020/10/26 15:15
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/10/26 15:15
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class TradeFragment extends BaseFragment {
    @BindView(R.id.status_bar_id)
    View statusBarId;
    @BindView(R.id.mViewPager)
    MyViewPager mViewPager;
    @BindView(R.id.liudong)
    TextView liudong;
    @BindView(R.id.duihuan)
    TextView duihuan;
    private ArrayList<Fragment> fragmentList;
    private MyFragmentAdapter adapter;
    private FragmentManager fragmentManager;
    // the fragment initialization parameters,e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_trade_fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }


    public static TradeFragment newInstance() {
        TradeFragment fragment = new TradeFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, "");
        args.putString(ARG_PARAM2, "");
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initView() {
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarId.getHeight());
        layoutParams.topMargin = StatusBarUtil.getStatusBarHeight(MyApplication.mContext);
        statusBarId.setLayoutParams(layoutParams);

        fragmentList = new ArrayList<>();
        fragmentList.add(new FlowCellFragment());
        fragmentList.add(new ExchangeFragment());
        fragmentManager = getChildFragmentManager();
        adapter = new MyFragmentAdapter(fragmentManager, fragmentList);
        mViewPager.setScrollable(false);
        mViewPager.setOffscreenPageLimit(2);
        mViewPager.setAdapter(adapter);
//        tabLayout.addOnTabSelectedListener(this);

        liudong.setTextSize( 18);
        duihuan.setTextSize( 15);
    }

    @OnClick({R.id.duihuan,
            R.id.liudong})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.liudong:
                mViewPager.setCurrentItem(0);
                liudong.setTextSize(  18);
                duihuan.setTextSize(  15);
                break;
            case R.id.duihuan:
                mViewPager.setCurrentItem(1);
                liudong.setTextSize(  15);
                duihuan.setTextSize(  18);
                break;
            default:
                break;
        }
    }


    public static class MyFragmentAdapter extends FragmentPagerAdapter {
        private List<Fragment> fragments;

        public MyFragmentAdapter(FragmentManager fm, List<Fragment> fragments) {
            super(fm);
            this.fragments = fragments;
        }

        @Override
        public Fragment getItem(int i) {
            return fragments.get(i);
        }


        @Override
        public int getCount() {
            return fragments.size();
        }
    }
}